package com.monkeybrother.thread.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @Desc
 * @Author houry
 * @Date 2021/4/5 15:05
 **/
public class FutureTaskTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newCachedThreadPool();
        System.out.println("~~~~~~~future task 开始进行业务的计算~~~~~~~~~");
        FutureTask<String> first = new FutureTask<>(new MyCallable(2, "加油！"));
        FutureTask<String> second = new FutureTask<>(new MyCallable(5, "努力的人儿！"));
        executor.submit(first);
        executor.submit(second);
        executor.shutdown();
        System.out.println("~~~~~~~主线程可以继续执行一些其他的任务~~~~~~~");
        System.out.println("最后的结果：" + first.get() + " " + second.get());
    }
}
